String Extraction


From the below string values, how can the strings "CCCCC" , "DDDDDDDDDDD" , "DDDDDDD VVVVVVV IIIIIIIII" & "DDDDDDD VVVVVVVV MMMMMMMMMM" be extracted ? Should I depend on a Reguular expression for this as well ??

/A/Copy/H/CCCCC/Feature
/A/Copy/H/DDDDDDDDDDD/Feature
/A/Copy/H/DDDDDDD VVVVVVV IIIIIIIII/Feature
/A/Copy/H/DDDDDDD VVVVVVVV MMMMMMMMMM/Feature

 

If there is already a post for this, please refirect (as I could not find one during my search in this forum)


HKrishnan - Mon Nov 23 04:49:16 EST 2015

Re: String Extraction
Mathias Mamsch - Mon Nov 23 04:56:21 EST 2015

Search the forum for "split string", you will probably find some example code. Regards, Mathias

Re: String Extraction
HKrishnan - Tue Nov 24 06:29:31 EST 2015

Mathias Mamsch - Mon Nov 23 04:56:21 EST 2015

Search the forum for "split string", you will probably find some example code. Regards, Mathias

I Did some search and was able to get the attached example so I tried converting my script to address the requirement and am facing some errors. Anything missing ??

 

Regexp ProjectName = regexp("^(/([a-zA-Z])/([a-zA-Z])/([a-zA-Z])/([a-zA-Z])/([a-zA-Z])$")                      
bool ReadProjectName(string DecodeCR, &FirstSlash, &A, &SecondSlash, &Copy, &ThirdSlash, &H, &FourthSlash, &NAME, &FifthSlash, &Feature)
{     
        if (ProjectName DecodeCR)
        {
   FirstSlash = DecodeCR[match 1]
   A = DecodeCR[match 2]
   SecondSlash = DecodeCR[match 3]
   Copy = DecodeCR[match 4]
   ThirdSlash = DecodeCR[match 5]
   H = DecodeCR[match 6]
   FourthSlash = DecodeCR[match 7]
   NAME = DecodeCR[match 8]
   FifthSlash = DecodeCR[match 9]
   Feature = DecodeCR[match 10]
   return(true)
        }
        else
        {  
   FirstSlash = ""
   A = ""
   SecondSlash = ""
   Copy = ""
   ThirdSlash = ""
   H = ""
   FourthSlash = ""
   NAME = ""
   FifthSlash = ""
   Feature = ""
   return(false)
        }
}
void Test_ReadProjectName(string DecodeCR)
{     
 string FirstSlash, A, SecondSlash, Copy, ThirdSlash, H, FourthSlash, NAME, FifthSlash, Feature
 bool Result = ReadProjectName(DecodeCR, FirstSlash, A, SecondSlash, Copy, ThirdSlash, H, FourthSlash, NAME, FifthSlash, Feature)
 print Result "\t" NAME "\n"
}
Test_ReadProjectName("/A/Copy/H/CCCCC/Feature")

 


Attachments

RegEx Example.dxl

Re: String Extraction
HKrishnan - Wed Nov 25 03:44:34 EST 2015

Thanks Mathias Mamsch

 

I was able to crack this by using us idea in the other thread

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014452144&ps=25

 

Created mention, continue typing for type aheadHere goes the code for the above requirement

 

Regexp re = regexp "/A/Copy/H/(.*)/Feature"

string s1 = "/A/Copy/H/CCCCC/Feature"

if (re s1 ) 
{
    print  s1[match 1] "\n"
}